package com.xiaoq.distribution.service.impl;

import com.xiaoq.distribution.entity.TicketOrderItemEntity;
import com.xiaoq.distribution.repository.ITicketOrderItemRepository;
import com.xiaoq.distribution.service.ITicketOrderItemService;
import com.xiaoq.vo.PagingVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chenjh on 2018/5/31.
 */
@Service
public class TicketOrderItemServiceImpl implements ITicketOrderItemService {

    @Autowired
    private ITicketOrderItemRepository ticketOrderItemRepository;

    @Override
    public boolean save(TicketOrderItemEntity ticketOrderItemEntity) {
        return ticketOrderItemRepository.save(ticketOrderItemEntity);
    }

    @Override
    public boolean updateById(TicketOrderItemEntity ticketOrderItemEntity) {
        return ticketOrderItemRepository.updateById(ticketOrderItemEntity);
    }

    @Override
    public boolean updateByOrderId(TicketOrderItemEntity ticketOrderItemEntity) {
        return ticketOrderItemRepository.updateByOrderId(ticketOrderItemEntity);
    }

    @Override
    public TicketOrderItemEntity getById(String id) {
        return ticketOrderItemRepository.getById(id);
    }

    @Override
    public List<TicketOrderItemEntity> getOrderItemList4CreatedTicketSettle(String orderId, String distributorId, String ticketId, Long minCreateTime, Long maxCreateTime, Integer payState) {
        return ticketOrderItemRepository.getOrderItemList(orderId, distributorId, ticketId, minCreateTime, maxCreateTime,payState);
    }

    @Override
    public List<TicketOrderItemEntity> getOrderItemList4UseTicketSettle(String shopOrderid, String distributorId, String ticketId, Long minUseTime, Long maxUseTime, Integer payState) {
        return ticketOrderItemRepository.getUseOrderItemList(shopOrderid, distributorId, ticketId, minUseTime, maxUseTime, payState);
    }

    @Override
    public List<TicketOrderItemEntity> getRefundOrderItemList(String shopOrderId, String distributorId, String ticketId, Long minRefundTime, Long maxRefundTime, Integer payState) {
        return ticketOrderItemRepository.getRefundOrderItemList(shopOrderId, distributorId, ticketId, minRefundTime, maxRefundTime, payState);
    }

    @Override
    public List<TicketOrderItemEntity> getListByShopOrderId(String shopOrderId) {
        if(StringUtils.isBlank(shopOrderId)){
            return new ArrayList<>(0);
        }
        return ticketOrderItemRepository.getListByShopOrderId(shopOrderId);
    }

    @Override
    public TicketOrderItemEntity getByTicketCode(String ticketCode) {
        if(StringUtils.isBlank(ticketCode)){
            return null;
        }
        return ticketOrderItemRepository.getByTicketCode(ticketCode);
    }

    @Override
    public long getUseOrderItemCountByOrderId(String shopOrderId) {
        if(StringUtils.isBlank(shopOrderId)){
            return 0L;
        }
        return ticketOrderItemRepository.getUseOrderItemCountByOrderId(shopOrderId);
    }

    @Override
    public List<TicketOrderItemEntity> getList4SettleRecord(String shopId, String orderIdOrItemIdOrTicketCode, Long useBeginTime, Long useEndTime, PagingVo pagingVo) {
        return ticketOrderItemRepository.getList4SettleRecord(shopId, orderIdOrItemIdOrTicketCode, useBeginTime, useEndTime, pagingVo);
    }

    @Override
    public long getCount4SettleRecord(String shopId, String orderIdOrItemIdOrTicketCode, Long useBeginTime, Long useEndTime) {
        return ticketOrderItemRepository.getCount4SettleRecord(shopId, orderIdOrItemIdOrTicketCode, useBeginTime, useEndTime);
    }
}
